import { Module } from '@nestjs/common';
// @nestjs/config : ConfigService:提供一些配置项  ConfigModule : 添加配置项
import { ConfigModule, ConfigService } from '@nestjs/config';
import { configuration } from './config';
import { TypeOrmModule, TypeOrmModuleOptions } from '@nestjs/typeorm';
// import { UsersController } from './modules/users/users.controller';
// import { UsersService } from './modules/users/users.service';
import { UsersModule } from './modules/users/users.module';
import { AuthModule } from './common/guard/auth.module';
import { APP_GUARD } from '@nestjs/core';
import { JwtAuthGuard } from './common/guard/auth.guard';
// import { AuthService } from './common/guard/auth.service;
import { OssModule } from './modules/oss/oss.module';
@Module({
  imports: [
    // load : 装载
    ConfigModule.forRoot({
      cache: true,
      load: [...configuration.load],
      isGlobal: true,
    }),
    TypeOrmModule.forRootAsync({
      imports: [ConfigModule],
      inject: [ConfigService],
      useFactory: (config: ConfigService) => {
        const entities = [`${__dirname}/**/*.entity{.ts,.js}`];
        console.log(entities);
        return {
          type: 'mysql',
          ...config.get('db.mysql'),
          entities: [`${__dirname}/**/*.entity{.ts,.js}`],
        } as TypeOrmModuleOptions;
      },
    }),
    UsersModule,
    AuthModule,
    OssModule, // oss模块
  ],
  controllers: [],
  providers: [{ provide: APP_GUARD, useClass: JwtAuthGuard }],
})
export class AppModule {}
